home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / QuickTime / Programming Stuff / Sample Code / Movie Toolbox / MovieBrowser / BrowserMaker.c next >
Encoding:
C/C++ Source or Header  |  1994-12-09  |  3.4 KB  |  143 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        BrowserMaker.c
  3.  
  4.     Written by:    Peter Hoddie
  5.  
  6.     Copyright:    © 1992-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8.     Change History (most recent first):
  9.   <1>         12/8/94        khs        changed the format of the file to the new look and feel
  10.  
  11.  
  12. */
  13.  
  14.  
  15. // INCLUDES
  16. #include <Aliases.h>
  17. #include <Files.h>
  18. #include <Movies.h>
  19. #include <QDOffscreen.h>
  20. #include <Resources.h>
  21. #include <Fonts.h>
  22.  
  23. #define PosterWidth 80
  24. #define PosterHeight 60
  25.  
  26.  
  27. // FUNCTIONS
  28. void main(void)
  29. {
  30.     StandardFileReply srcReply;
  31.     SFReply dstReply;
  32.     FSSpec newDoc;
  33.     OSType movieType = 'MooV';
  34.     Point where = {50, 50};
  35.     short dstResRef;
  36.     short fileIndex = 1;
  37.     Rect totalRect = {0,0,0,0};
  38.     Rect posterRect = {0,0,PosterHeight,PosterWidth};
  39.     GWorldPtr posterGW;
  40.     Handle rectH;
  41.     char zero = 0;
  42.     short resID = 128;
  43.  
  44.     // initialize the world
  45.     InitGraf(&qd.thePort);
  46.     InitFonts();
  47.     InitWindows();
  48.     InitMenus();
  49.     TEInit();
  50.     InitDialogs(0L);
  51.     InitCursor();
  52.     MaxApplZone();
  53.     EnterMovies();
  54.  
  55.     StandardGetFilePreview(nil, 1, &movieType, &srcReply);
  56.     if (!srcReply.sfGood) return;
  57.  
  58.     SFPutFile(where, "\pCreate Page Doc:", "\pNewPageDoc", nil, &dstReply);
  59.     if (!dstReply.good) return;
  60.  
  61.     FSMakeFSSpec(dstReply.vRefNum, 0, dstReply.fName, &newDoc);
  62.     FSpDelete(&newDoc);
  63.     FSpCreateResFile(&newDoc, 'aNdY', 'Dalí', -2);
  64.     dstResRef = FSpOpenResFile(&newDoc, fsRdWrPerm);
  65.     if (ResError()) return;
  66.  
  67.     // make a gworld for creating posters
  68.     if (NewGWorld(&posterGW, 16, &posterRect, 0, 0, 0) != noErr) return;
  69.     SetGWorld(posterGW, 0);
  70.  
  71.     do {
  72.         OSErr err;
  73.         HFileParam pb;
  74.         FSSpec movieFile;
  75.         Str255 name;
  76.         short movieRes;
  77.         
  78.         pb.ioVRefNum = srcReply.sfFile.vRefNum;
  79.         pb.ioFDirIndex = fileIndex++;
  80.         pb.ioDirID = srcReply.sfFile.parID;
  81.         pb.ioNamePtr = name;
  82.         err = PBHGetFInfoSync((HParmBlkPtr)&pb);
  83.         if (err) break;
  84.  
  85.         if (pb.ioFlFndrInfo.fdType != 'MooV') continue;
  86.  
  87.         FSMakeFSSpec(srcReply.sfFile.vRefNum, srcReply.sfFile.parID, name, &movieFile);
  88.         if (OpenMovieFile(&movieFile, &movieRes, fsRdPerm) == noErr) {
  89.             Movie newMovie;
  90.  
  91.             err = NewMovieFromFile(&newMovie, movieRes, nil, nil,
  92.                  0, nil);
  93.             CloseMovieFile(movieRes);
  94.             if (!err) {
  95.                  Rect movieBox;
  96.                  AliasHandle newAlias = 0;
  97.                  PicHandle newPict;
  98.                  PicHandle poster;
  99.  
  100.                  // accumlate the bounds
  101.                  GetMovieBox(newMovie, &movieBox);
  102.                  OffsetRect(&movieBox, -movieBox.left, -movieBox.top);
  103.                  if (EmptyRect(&totalRect))
  104.                      totalRect = movieBox;
  105.                  else
  106.                      UnionRect(&movieBox, &totalRect, &totalRect);
  107.  
  108.                 // add the alias
  109.                 NewAlias(&newDoc, &movieFile, &newAlias);
  110.                 AddResource((Handle)newAlias, rAliasType, resID, movieFile.name);
  111.                 WriteResource((Handle)newAlias);
  112.                 ReleaseResource((Handle)newAlias);
  113.  
  114.                 // add the poster
  115.                  poster = GetMoviePosterPict(newMovie);
  116.                  EraseRect(&posterRect);
  117.                  DrawPicture(poster, &posterRect);
  118.                  KillPicture(poster);
  119.                  newPict = OpenPicture(&posterRect);
  120.                      CopyBits((BitMap *)*posterGW->portPixMap, (BitMap *)*posterGW->portPixMap,
  121.                              &posterRect, &posterRect, ditherCopy, nil);
  122.                  ClosePicture();
  123.                 AddResource((Handle)newPict, 'PICT', resID++, (StringPtr)&zero);
  124.                 WriteResource((Handle)newPict);
  125.                 ReleaseResource((Handle)newPict);
  126.  
  127.                 DisposeMovie(newMovie);
  128.              }
  129.         }
  130.  
  131.  
  132.     } while (true);
  133.  
  134.     // add the bounds rect
  135.     InsetRect(&totalRect, -50, -25);
  136.     PtrToHand((Ptr)&totalRect, &rectH, sizeof(totalRect));
  137.     AddResource((Handle)rectH, 'RECT', 128, (StringPtr)&zero);
  138.     WriteResource((Handle)rectH);
  139.     ReleaseResource((Handle)rectH);
  140.  
  141.     CloseResFile(dstResRef);
  142. }
  143.